package org.example.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.example.client.TestOpenFeignClient;
import org.example.service.Impl.SeataServiceImpl;
import org.example.service.Impl.TestServiceImpl;
import org.example.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Random;

@RestController
@RefreshScope
public class TestController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private TestOpenFeignClient testOpenFeignClient;
    @Autowired
    private TestServiceImpl testService;
    @Autowired
    private SeataServiceImpl seataService;
    @Value("${test}")
    private String test;
    @GetMapping("/test")
    public String test() {
        testService.test();
        return restTemplate.getForObject("http://cloud-users/test", String.class);
    }
    @GetMapping("/testOpenFeign")
    public String testOpenFeign() {
        System.out.println("调用");
        System.out.println(test);
        testService.test();
       return testOpenFeignClient.testOpenFeign();
    }
    @GetMapping("/testRd")
    public String testRd() throws InterruptedException {
     int x = new Random().nextInt(100);
     System.out.println(x);
     if (x>50){
         int i=1/0;
         Thread.sleep(300);
     }
     return x+"";
    }
    @GetMapping("/seata")
    public void seata() {
        seataService.testSeata();
    }
    @SentinelResource("/testss")
    @GetMapping("/tests")
    public String tests(@RequestParam("a") String a) {
        System.out.println(a);
        return "111";
    }
}
